import { ref } from 'vue';
import { GameKernel, EVENTS } from '../game';
import type { ItemRarity, ItemType } from '../game/data/item/type';

const kernel = GameKernel.inst;

const state = ref(kernel.inventorySystem.getUISnapshot());

kernel.bus.on(EVENTS.INVENTORY_STATE_UPDATE, () => {
  state.value = kernel.inventorySystem.getUISnapshot();
});
kernel.bus.on(EVENTS.GAME_LOADED, () => {
  state.value = kernel.inventorySystem.getUISnapshot();
});

const backpackState = ref<{ rarity: ItemRarity[]; type: ItemType[] }>({
  rarity: [],
  type: [],
});

export function useInventory() {
  state.value = kernel.inventorySystem.getUISnapshot();
  return { state, backpackState };
}
